package com.test.practice.genericity.custom;

import java.util.List;

/**
 * 自定义泛型类 Demo
 *
 * @Description: 自定义泛型类
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-09
 * =======================
 * @Version: 1.1.2.0
 */
public class CustomDemo {

    public static void main(String[] args) {

//        m1();

//        m2();


        Customer<String> customer = new Customer<>();
        Integer[] arr = {1, 4, 5};
        String[] arrStr = {"aa", "cc", "ee"};
        Long[] arrLong = {2L, 4L, 6L};

        //泛型方法在调用时，指明泛型类型
        List<Integer> list = customer.copyFromArrayList(arr);
        List<String> list_str = customer.copyFromArrayList(arrStr);
        List<Long> list_long = Customer.staticCopyFromArrayList(arrLong);

        System.out.println(list);
        System.out.println(list_str);
        System.out.println(list_long);
    }

    private static void m2() {
        SubCustomer sc = new SubCustomer();
        //如果这里SubCustomer在继承类的时候就已经指定了泛型，则子类在实现的时候不需要
        sc.setCustomT(123);

        SubCustomer1<String> sc1 = new SubCustomer1();
        //如果这里SubCustomer在继承类的时候就没有指定泛型，则子类在实现的时候需要指定
        sc1.setCustomT("123");
    }

    private static void m1() {
        //如果定义了泛型，实例化没有指明类的泛型，则认为是Object类型
        Customer customer1 = new Customer();
        customer1.setCustomT("");
        customer1.setCustomT(123);

        Customer<String> customer2 = new Customer();
        customer2.setCustomT("");
//        customer2.setCustomT(123); 如果实例化指明泛型，赋值不同类，则编译报错
    }


}
